package com.shxy.cloudclassroom.config;

import com.shxy.cloudclassroom.utils.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig  implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //viewController 请求路径    viewName: 跳转视图
        registry.addViewController("/").setViewName("redirect:/login");
        registry.addViewController("login").setViewName("login");
        registry.addViewController("register").setViewName("register");
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加登录拦截器，并指定需要拦截的路径
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/user/**") // 拦截所有/user/开头的请求
                .excludePathPatterns("/user/login", "/user/register", "/user/check", "/user/code"); // 排除不需要登录验证的路径
    }
}
